<?php

namespace core;

class Request
{
    /* @var string */
    private $method; //请求方法
    /* @var string */
    private $uri; //请求路径
    /* @var array */
    private $queryParams; //get 数据
    /* @var array */
    private $postData; //post 数据

    /*@var array */
    private $params = []; //路由参数

    public function __construct()
    {
        $this->method      = $_SERVER['REQUEST_METHOD'];
        $this->uri         = $_SERVER['REQUEST_URI'];
        $this->queryParams = $_GET;
        $this->postData    = $_POST;
    }

    public function getMethod(): string
    {
        return $this->method;
    }

    public function getUri(): string
    {
        return explode('?', $this->uri, 2)[0];
    }

    public function getQueryParams(): array
    {
        return $this->queryParams;
    }

    public function getPostData(): array
    {
        return $this->postData;
    }

    public function getParams(): array
    {
        return $this->params;
    }

    public function setParams(array $val): void
    {
        $this->params = $val;
    }

    public function getParam(string $key)
    {
        return $this->params[$key];
    }
}
